# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sheldon
pkgver=0.6.6 # TODO: Enable system libgit2 with next update
pkgrel=1
pkgdesc="Fast, configurable, shell plugin manager"
url="https://github.com/rossmacarthur/sheldon"
arch="aarch64 armhf armv7 ppc64le x86 x86_64"  # blocked by rust/cargo
license="MIT OR Apache-2.0"
makedepends="
	cargo
	curl-dev
	libgit2-dev
	libssh2-dev
	openssl-dev
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/rossmacarthur/sheldon/archive/$pkgver/sheldon-$pkgver.tar.gz
	$pkgname-9aa06fd-fix-tests.patch::https://github.com/rossmacarthur/sheldon/commit/9aa06fdd5cb284daae8c48648d614e3823f3f9f3.patch
	"

export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_LTO="true"
export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"
export CARGO_PROFILE_RELEASE_PANIC="abort"

export LIBSSH2_SYS_USE_PKG_CONFIG=1  # use system libssh2

prepare() {
	default_prepare

	# Build against system libgit2.
	# XXX: Disabled for now since libgit2 1.4.X is not supported.
	#sed -i 's/"vendored-libgit2"//' Cargo.toml

	cargo fetch --locked
}

build() {
	cargo build --frozen --release
}

check() {
	# Skipped tests - https://github.com/rossmacarthur/sheldon/issues/140
	GIT_COMMIT_HASH="unknown" \
	GIT_COMMIT_SHORT_HASH="unknown" \
	GIT_COMMIT_DATE="unknown" \
	cargo test --frozen -- \
		--skip=lock_and_source_github_git \
		--skip=locked_config_clean \
		--skip=source_lock_git_git_with_checkout
}

package() {
	install -D -m755 target/release/sheldon -t "$pkgdir"/usr/bin/

	install -D -m644 completions/sheldon.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_sheldon
	install -D -m644 completions/sheldon.bash \
		"$pkgdir"/usr/share/bash-completion/completions/sheldon
}

sha512sums="
95ac78ece52786cbfabe395c9c934ed3aa2e59e1101838a129ac11338ad88af24f8142ccc4038c0fbf1620e255f9846655cbe2ac2cb604f6f782efa8b95ede09  sheldon-0.6.6.tar.gz
49b8319cce1452f73c2b3e889d330efc1dd2f3d634433f88bbaa094d1ea30d819b0e5fd24320ccfb06160de87e9e04fc0e90dbdc89a4adea7c40d90390fbdfde  sheldon-9aa06fd-fix-tests.patch
"
